package common;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;

import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import cn.hutool.json.XML;

public class Sout {

	public static void main(String[] args) {
		
		
		/*String s1 = "市直医保|http://499v7q1655.imdo.co/cash/create";
		System.out.println(s1.contains("市直医保"));
		System.out.println((int)((Math.random()*9+1)*100000));
		
		HashMap<String, String> paramsMap = new HashMap();
		paramsMap.put("payAuthNo", "AUTH1234567898765432");
		paramsMap.put("payOrdId", "QRD1234567898765432");
		paramsMap.put("totlRefdAmt", "55");
		java.math.BigDecimal amtFee = getBigDecim(Fen2Yuan((String)paramsMap.get("totlRefdAmt")));
		
		
		Date date = new Date();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
		int randomFux = (int)((Math.random()*9+1)*100000);
		StringBuffer sb = new StringBuffer();
		sb.append("{\"PayAuthNo\": \"");
		sb.append(paramsMap.get("payAuthNo"));
		sb.append("\", \"RefundFlowNo\": \"");
		sb.append(sdf.format(date));
		sb.append(randomFux);
		sb.append("\", \"PayOrdId\": \"");
		sb.append(paramsMap.get("payOrdId"));
		sb.append("\", \"OrderAmt\": \"");
		sb.append(amtFee);
		sb.append("\"}");
		
		System.out.println(sb.toString());
		System.out.println(JSONUtil.toXmlStr(new JSONObject(sb.toString())));
		
		System.out.println(String.format( "市直医保退费订单号=%s%d\r\n" , sdf.format(date) , randomFux));	
		*/
	}
	
	/**
	 * 较为安全的string -- > BigDecimal转换
	 * @author: 1952593542
	 * @Date: 2022年10月27日下午4:47:18
	 * @param origin
	 * @return
	 */
	public static BigDecimal getBigDecim(String origin) {
		if(origin != null) {
			java.math.BigDecimal bd = new java.math.BigDecimal(origin);
			return bd;
		} else {
			return  new java.math.BigDecimal("0");
		}
	}
	
	 /* 将交易金额(可能含有2位小数)由分到元的转换 */
		public static String Fen2Yuan(String Money)
	    {
	        java.math.BigDecimal aa = new java.math.BigDecimal(Money);
	        java.text.DecimalFormat df = new java.text.DecimalFormat("0.00");
	        return df.format(aa.doubleValue()/100);
	    }
}
